<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrderDiscount extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('order_discount', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('orderId')->default(0)->comment("kf_orders表id");
            $table->unsignedTinyInteger('discountType')->default(0)->comment("折扣类型，如满减券、代金券");
            $table->unsignedInteger('discountNum')->default(0)->comment("优惠值 90 折 或者 500 分等 ");
            $table->unsignedInteger('discountPrice')->default(0)->comment("折扣金额分 ");

            // 统一表字段
            $table->integer('createdAt')->default(0)->comment('创建时间');
            $table->integer('createdByUid')->default(0)->comment('创建人');
            $table->integer('updatedAt')->default(0)->comment('修改时间');
            $table->integer('updatedByUid')->default(0)->comment('修改人');
            $table->integer('isDeleted')->default(0)->comment('是否删除');

            // 索引部分
            $table->index('orderId', 'idx_orderId');  // 索引

            $table->collation = 'utf8mb4_general_ci';
        });

        $prefix = config('other.DB_PREFIX', '');
        \Illuminate\Support\Facades\DB::statement("ALTER TABLE `{$prefix}order_discount` COMMENT = '折扣表'"); //表注释
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('order_discount');
    }
}
